﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace kim.Web.Admin.Company
{
    public partial class About1 : UI.ManagePage
    {
        protected int typeid, fid;
        Model.WebInfo model;
        protected void Page_Load(object sender, EventArgs e)
        {
            typeid = Common.KIMRequest.GetInt("typeid", 0);
            fid = Common.KIMRequest.GetInt("fid", 0);
            if (!IsPostBack)
            {
                this.labtitle.Text = labtitle2.Text = "介绍内容";
               
                GetAbout();
            }
        }
        public void GetAbout()
        {
            List<Model.WebInfo> model = new BLL.WebInfo().GetModelList("TypeID=" + typeid + " and ChannelID=" + fid);
            if (model.Count > 0)
            {
                ViewState["type"] = "Edit";
                txt_Content.Value = model[0].Content;
                ViewState["id"] = model[0].ID;
            }
            else
                ViewState["type"] = "Add";
        }
      

        protected void btnSave_Click(object sender, EventArgs e)
        {
            model = new Model.WebInfo();
            BLL.WebInfo bll = new BLL.WebInfo();
            model.Content = txt_Content.Value;
            model.Name = labtitle2.Text;
            model.TypeID = typeid;
            model.ChannelID = fid;
            if (ViewState["type"].ToString() == "Add")
            {
                if (bll.Add(model))
                    lbmsg.Text = "添加成功";
                else
                    lbmsg.Text = "添加失败";
            }
            if (ViewState["type"].ToString() == "Edit")
            {
                model.ID = Convert.ToInt32(ViewState["id"]);
                if (bll.Update(model))
                    lbmsg.Text = "修改成功";
                else
                    lbmsg.Text = "修改失败";
            }
        }
    }
}